import Vue from 'vue'
import Vuex from 'vuex'

import {
	versionConfig
} from '@/common/config/versionConfig.js'

Vue.use(Vuex) // vue的插件机制

// Vuex.Store 构造器选项
const store = new Vuex.Store({
	// 为了不和页面或组件的data中的造成混淆，state中的变量前面建议加上$符号
	state: {
		// 用户信息
		userInfo: {},
		// 标签列表
		tags: [],
		lessee: '',
		clientInfo: {},
		dynamicTabbar: [],
		currentLocation: {},
	},
	mutations: {
		userInfo(state, userInfo){
			state.userInfo = userInfo
		},
		tags(state, tags) {
			state.tags = tags
		},
		dynamicTabbar(state, dynamicTabbar) {
			state.dynamicTabbar = dynamicTabbar
		},
		clientInfo(state, clientInfo) {
			state.clientInfo = clientInfo
		},
		currentLocation(state, currentLocation) {
			state.currentLocation = currentLocation
		},
		lessee(state, lessee) {
			state.lessee = lessee
			state.token = lessee + '_token'
			state.userInfo = lessee + '_userInfo'

			// #ifdef APP-PLUS
			state.channel = 'APP'
			state.version = plus.runtime.version
			state.clientname = lessee + '_app'
			// #endif
			// #ifdef MP-WEIXIN
			state.channel = 'WX-APPLET'
			state.version = versionConfig.miniproVersion
			state.clientname = lessee + '_minipro'
			// #endif
			// #ifdef MP-ALIPAY
			state.channel = 'ALI-APPLET'
			state.version = versionConfig.miniproVersion
			state.clientname = lessee + '_miniproForAli'
			// #endif
			// #ifdef H5
			state.channel = 'H5-APPLET'
			state.version = versionConfig.miniproVersion
			state.clientname = lessee + '_minipro'
			// #endif
		},
	},
	getters: {
		getLessee(state) {
			return state.lessee
		},
		getUserInfo(state) {
			return state.userInfo
		},
		getTags(state) {
			return state.tags
		},
		getDynamicTabbar(state) {
			return state.dynamicTabbar
		},
		clientInfo(state) {
			return state.clientInfo
		},
		getCurrentLocation(state) {
			return state.getCurrentLocation
		},
	}
})

export default store
